﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

using SchoolSTEDAL.STEEntities;

namespace SchoolService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "SchoolService" in code, svc and config file together.
    public class SchoolService : ISchoolService
    {

        #region ISchoolService Members

        public Student GetStudent(string name)
        {
            using (SchoolDBContext ctx = new SchoolDBContext())
            {

                var student = from s in ctx.Students.Include("Courses").Include("StudentAddress")
                              where s.StudentName == name
                              select s;

                return student.FirstOrDefault<Student>();
            
            }
        }

        public void UpdateStudent(Student student)
        {
            using (SchoolDBContext ctx = new SchoolDBContext())
            {
                ctx.Students.ApplyChanges(student);
                ctx.SaveChanges();
            }         
   
        }

        public Standard GetStandard(string standardName)
        {
            using (SchoolDBContext ctx = new SchoolDBContext())
            {

                var std = from s in ctx.Standards.Include("Teachers")
                              where s.StandardName == standardName
                              select s;

                return std.FirstOrDefault<Standard>();

            }
        }

        public void UpdateStandard(Standard standard)
        {
            using (SchoolDBContext ctx = new SchoolDBContext())
            {
                ctx.Standards.ApplyChanges(standard);
                ctx.SaveChanges();
            }         
        }

        #endregion
    }
}
